<template>
	<view class="page">
		<view class="padding-bottom">
			<view class="text-lg padding-tb-sm text-bold">尊敬的用户：</view>
			<view class="text-df">
				为满足《中华人民共和国网络安全法》及有关部门的要求，我们要收集您的姓名和身份证号码，以证实您的个人身份。
			</view>
		</view>
		<view class=" light bg-orange border" style="border-radius: 20rpx;">
			<view class="text-bold text-lg padding-sm padding-tb text-black">
				请使用本人有效身份证件
			</view>
			<view class="padding-sm bg-white" style="border: 1px solid #fde6d2;border-radius: 0 0 20rpx 20rpx;">
				<view class="uni-form-item uni-column">
					<view class="title">姓名</view>
					<input class="uni-input" placeholder-style="color:#adadad;font-size:29rpx"
						v-model="authInfo.realname" placeholder="请输入你的真实姓名" :disabled="authInfo.auth_status == 1 || authInfo.auth_status == 3" />
				</view>
				<view style="border: 1px solid #f6f6f6;" class="margin-tb-sm"></view>
				<view class="uni-form-item uni-column padding-bottom-sm">
					<view class="title">身份证号</view>
					<input class="uni-input" placeholder-style="color:#adadad;font-size:29rpx" v-model="authInfo.idcard"
						placeholder="请输入您的身份证号" :disabled="authInfo.auth_status == 1 || authInfo.auth_status == 3" />
				</view>
				<roc-line :height="10"></roc-line>
				<view class="text-sm text-red">
					注：信息认证成功后不可更改，请确认无误后在提交
				</view>
			</view>
		</view>
		<view class="padding flex flex-direction" v-if="authInfo.auth_status == 2">
			<button class="cu-btn bg-red margin-tb-sm lg" @click="save">重新提交</button>
		</view>
		<view class="padding flex flex-direction" v-if="authInfo.auth_status == 3">
			<button class="cu-btn bg-red margin-tb-sm lg">认证中</button>
		</view>
		<view class="padding flex flex-direction" v-if="authInfo.auth_status == 4">
			<button class="cu-btn bg-red margin-tb-sm lg" @click="save">提交认证</button>
		</view>
		<view class="text-grey text-xs text-center">
			平台承诺 保障您的隐私安全
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				authInfo: {}
			}
		},
		onLoad() {
			this.getAuthInfo()
		},
		methods: {

			save() {
				let that = this
				let reg1 = /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/; //正则表达式定义身份证号正确格式
				if (!this.authInfo.idcard) { //判断如果身份证号（this.card)num）为空，提示用户输入身份证号
					uni.showToast({
						title: '请输入身份证号',
						icon: 'none'
					})
					return
				}
				
				if (!reg1.test(this.authInfo.idcard)) { //判断身份证号格式时候正确
					uni.showToast({
						title: '请输入正确的身份证号',
						icon: 'none'
					})
					return
				}

				this.request.httpTokenRequest({
					url: "user/auth",
					method: "post",

				}, this.authInfo).then(res => {
					if (res.code == 0) {
						this.$util.modal(res.msg)
					} else {
						this.$util.msg(res.msg)
						return
					}
				}, error => {})
			},

			getAuthInfo() {
				let that = this
				this.request.httpTokenRequest({
					url: "user/auth",
					method: "get"
				}, {}).then(res => {
					if (res.code == 0) {
						that.authInfo = res.data
					} else {
						this.$util.msg(res.msg)
						return
					}
				}, error => {})
			}
		}
	}
</script>

<style lang="scss">
	.page {
		background-color: #fff;
		padding: 20rpx 50rpx; 
		height: 100vh;
	}

	.title {
		padding: 10rpx 0 20rpx 0;
		font-size: 30rpx;
		color: #333;
	}

	.uni-input {}
</style>